home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / LSODE.h < prev    next >
C/C++ Source or Header  |  1996-07-24  |  4KB  |  183 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_LSODE_h)
  24. #define octave_LSODE_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #if 0
  31. class ostream;
  32. #endif
  33.  
  34. #include <cfloat>
  35. #include <cmath>
  36.  
  37. #include "ODE.h"
  38.  
  39. class
  40. LSODE_options
  41. {
  42. public:
  43.  
  44.   LSODE_options (void) { init (); }
  45.  
  46.   LSODE_options (const LSODE_options& opt) { copy (opt); }
  47.  
  48.   LSODE_options& operator = (const LSODE_options& opt)
  49.     {
  50.       if (this != &opt)
  51.     copy (opt);
  52.  
  53.       return *this;
  54.     }
  55.  
  56.   ~LSODE_options (void) { }
  57.  
  58.   void init (void)
  59.     {
  60.       double sqrt_eps = ::sqrt (DBL_EPSILON);
  61.  
  62.       x_absolute_tolerance = sqrt_eps;
  63.       x_initial_step_size = -1.0;
  64.       x_maximum_step_size = -1.0;
  65.       x_minimum_step_size = 0.0;
  66.       x_relative_tolerance = sqrt_eps;
  67.     }
  68.  
  69.   void copy (const LSODE_options& opt)
  70.     {
  71.       x_absolute_tolerance = opt.x_absolute_tolerance;
  72.       x_initial_step_size = opt.x_initial_step_size;
  73.       x_maximum_step_size = opt.x_maximum_step_size;
  74.       x_minimum_step_size = opt.x_minimum_step_size;
  75.       x_relative_tolerance = opt.x_relative_tolerance;
  76.     }
  77.  
  78.   void set_default_options (void) { init (); }
  79.  
  80.   void set_absolute_tolerance (double val)
  81.     { x_absolute_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); }
  82.  
  83.   void set_initial_step_size (double val)
  84.     { x_initial_step_size = (val >= 0.0) ? val : -1.0; }
  85.  
  86.   void set_maximum_step_size (double val)
  87.     { x_maximum_step_size = (val >= 0.0) ? val : -1.0; }
  88.  
  89.   void set_minimum_step_size (double val)
  90.     { x_minimum_step_size = (val >= 0.0) ? val : 0.0; }
  91.  
  92.   void set_relative_tolerance (double val)
  93.     { x_relative_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); }
  94.  
  95.   double absolute_tolerance (void)
  96.     { return x_absolute_tolerance; }
  97.  
  98.   double initial_step_size (void)
  99.     { return x_initial_step_size; }
  100.  
  101.   double maximum_step_size (void)
  102.     { return x_maximum_step_size; }
  103.  
  104.   double minimum_step_size (void)
  105.     { return x_minimum_step_size; }
  106.  
  107.   double relative_tolerance (void)
  108.     {  return x_relative_tolerance; }
  109.  
  110. private:
  111.  
  112.   double x_absolute_tolerance;
  113.   double x_initial_step_size;
  114.   double x_maximum_step_size;
  115.   double x_minimum_step_size;
  116.   double x_relative_tolerance;
  117. };
  118.  
  119. class
  120. LSODE : public ODE, public LSODE_options
  121. {
  122. public:
  123.  
  124.   LSODE (void);
  125.  
  126.   LSODE (int n);
  127.   
  128.   LSODE (const ColumnVector& state, double time, const ODEFunc& f);
  129.  
  130.   ~LSODE (void) { }
  131.  
  132.   void force_restart (void);
  133.  
  134.   void set_stop_time (double t);
  135.   void clear_stop_time (void);
  136.  
  137.   ColumnVector do_integrate (double t);
  138.  
  139.   Matrix do_integrate (const ColumnVector& tout);
  140.  
  141. #if 0
  142.   void integrate (int nsteps, double tstep, ostream& s);
  143. #endif
  144.  
  145.   Matrix integrate (const ColumnVector& tout)
  146.     { return do_integrate (tout); }
  147.  
  148.   Matrix integrate (const ColumnVector& tout, const ColumnVector& tcrit);
  149.  
  150. private:
  151.  
  152.   double stop_time;
  153.   int stop_time_set;
  154.  
  155.   int n;
  156.   int integration_error;
  157.   int restart;
  158.   int method_flag;
  159.   Array<int> iwork;
  160.   Array<double> rwork;
  161.   int istate;
  162.   int itol;
  163.   int itask;
  164.   int iopt;
  165.   int liw;
  166.   int lrw;
  167.   int working_too_hard;
  168.   int sanity_checked;
  169.  
  170.   friend int lsode_f (int *neq, double *t, double *y, double *ydot);
  171.  
  172.   friend int lsode_j (int *neq, double *t, double *y, int *ml, int *mu,
  173.               double *pd, int *nrowpd);
  174. };
  175.  
  176. #endif
  177.  
  178. /*
  179. ;;; Local Variables: ***
  180. ;;; mode: C++ ***
  181. ;;; End: ***
  182. */
  183.